package com.qfedu.service.impl;

import com.qfedu.mapper.BranchMapper;
import com.qfedu.model.Branch;
import com.qfedu.model.Branch;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.BranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@Service
public class BranchServiceImpl implements BranchService {
    @Autowired
    private BranchMapper branchMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        long count = branchMapper.count();
        pageResult.setTotal(count);
        List<Branch> page = branchMapper.findPage((currentPage - 1) * pageSize, pageSize);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    public int addBranch(Branch branch) {
        branch.setUpdatetime(new Date());
        return branchMapper.addBranch(branch);
    }

    @Override
    public Branch findById(String bid) {
        return   branchMapper.findById(bid);
    }

    @Override
    public int editBranch(Branch branch) {
        branch.setUpdatetime(new Date());
        int i = branchMapper.editBranch(branch);
        return i;
    }

    @Override
    public int deleteByPid(String bid) {
        return branchMapper.deleteByPid(bid);
    }

    @Override
    public List<Branch> findByPid(int pid) {
        return branchMapper.findByPid(pid);
    }
}